package com.zyb.patient.activity;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.zyb.patient.R;
import com.zyb.patient.adapter.MyViewPageAdapter;
import com.zyb.patient.service.DbSqliteService;
import com.zyb.patient.util.LogUtil;

public class GuideActivity extends BaseActivity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_guide);

		ViewPager mViewPager = (ViewPager) findViewById(R.id.viewPager);
		mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
		// mPage0 = (ImageView) findViewById(R.id.page0);
		// mPage1 = (ImageView) findViewById(R.id.page1);
		// mPage2 = (ImageView) findViewById(R.id.page2);
		// 将要分页显示的View装入数组中
		LayoutInflater mLi = LayoutInflater.from(this);
		View view1 = mLi.inflate(R.layout.activity_guide_view, null);
		ImageView img1 = (ImageView) view1.findViewById(R.id.img);
		img1.setBackgroundResource(R.drawable.guide1);

		View view2 = mLi.inflate(R.layout.activity_guide_view, null);
		ImageView img2 = (ImageView) view2.findViewById(R.id.img);
		img2.setBackgroundResource(R.drawable.guide2);

		View view3 = mLi.inflate(R.layout.activity_guide_view, null);
		ImageView img3 = (ImageView) view3.findViewById(R.id.img);
		img3.setBackgroundResource(R.drawable.guide3);
		Button btn = (Button) view3.findViewById(R.id.btn);
		btn.setVisibility(View.VISIBLE);

		/*
		 * View view4 = mLi.inflate(R.layout.layout_guide_view, null); ImageView
		 * img4 = (ImageView) view4.findViewById(R.id.img);
		 * img4.setBackgroundResource(R.drawable.page03);
		 * 
		 * View view5 = mLi.inflate(R.layout.layout_guide_view, null); ImageView
		 * img5 = (ImageView) view5.findViewById(R.id.img);
		 * img5.setBackgroundResource(R.drawable.page04);
		 */

		// 每个页面的view数据
		ArrayList<View> views = new ArrayList<View>();
		views.add(view1);
		views.add(view2);
		views.add(view3);
		// views.add(view4);
		// views.add(view5);

		// 填充ViewPager的数据适配器
		PagerAdapter mPagerAdapter = new MyViewPageAdapter(views);
		mViewPager.setAdapter(mPagerAdapter);
	}

	public class MyOnPageChangeListener implements OnPageChangeListener {
		@Override
		public void onPageSelected(int arg0) {
			switch (arg0) {
			case 0:
				// mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
				// mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
				break;
			case 1:
				// mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
				// mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page));
				// mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page));
				break;
			case 2:
				// mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
				// mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
				// mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page));
				break;
			}
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
		}
	}

	public void startbutton(View v) {
		db.modifyConfigItem("isFirst", "1");
		Intent it;
		if ("0".equals(db.getConfigItem(DbSqliteService.USER_ID))) {
			it = new Intent(this, UserLoginActivity.class);
			it.putExtra("source", "1");
		} else {
			it = new Intent(this, MainActivity.class);
		}
		startActivity(it);
		finish();
	}

}
